package com.itheima.dubbo.mongodb.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.commons.model.mongo.Log;
import com.itheima.dubbo.interfaces.LogApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

/**
 * @Auther: alongchan
 * @Date: 2021/12/21 14:11
 * @Description:
 */

@Service
public class LogApiImpl implements LogApi {
    @Autowired
    private MongoTemplate mongoTemplate;
    //查询用户所有日志
    @Override
    public List<Log> findUserLogRecord(Integer page, Integer pageSize, Long userId) {
        List<Log> logs = mongoTemplate.find(Query.query(Criteria.where("userId").is(userId)), Log.class);
        return logs;
    }

    //用户登录
    @Override
    public void add(Log log) {
        mongoTemplate.insert(log);
    }
}
